<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>Class: JobBoss::Job</title>

	<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />

	<script src="../js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="../js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>

</head>
<body class="class">

	<div id="metadata">
		<div id="home-metadata">
			<div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../index.html">Home</a>
          <a href="../index.html#classes">Classes</a>
          <a href="../index.html#methods">Methods</a>
        </h3>
			</div>
		</div>

		<div id="file-metadata">
			<div id="file-list-section" class="section">
				<h3 class="section-header">In Files</h3>
				<div class="section-body">
					<ul>
					
						<li><a href="../lib/job_boss/job_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
							class="thickbox" title="lib/job_boss/job.rb">lib/job_boss/job.rb</a></li>
					
					</ul>
				</div>
			</div>

			
		</div>

		<div id="class-metadata">

			<!-- Parent Class -->
			
			<div id="parent-class-section" class="section">
				<h3 class="section-header">Parent</h3>
				
				<p class="link">ActiveRecord::Base</p>
				
			</div>
			

			<!-- Namespace Contents -->
			

			<!-- Method Quickref -->
			
			<div id="method-list-section" class="section">
				<h3 class="section-header">Methods</h3>
				<ul class="link-list">
					
					<li><a href="#method-c-call_path">::call_path</a></li>
					
					<li><a href="#method-c-delete_jobs_before">::delete_jobs_before</a></li>
					
					<li><a href="#method-c-pending_paths">::pending_paths</a></li>
					
					<li><a href="#method-c-result_hash">::result_hash</a></li>
					
					<li><a href="#method-c-wait_for_jobs">::wait_for_jobs</a></li>
					
					<li><a href="#method-i-assigned%3F">#assigned?</a></li>
					
					<li><a href="#method-i-cancel">#cancel</a></li>
					
					<li><a href="#method-i-cancelled%3F">#cancelled?</a></li>
					
					<li><a href="#method-i-completed%3F">#completed?</a></li>
					
					<li><a href="#method-i-dispatch">#dispatch</a></li>
					
					<li><a href="#method-i-error">#error</a></li>
					
					<li><a href="#method-i-mark_as_cancelled">#mark_as_cancelled</a></li>
					
					<li><a href="#method-i-mark_as_completed">#mark_as_completed</a></li>
					
					<li><a href="#method-i-mark_as_started">#mark_as_started</a></li>
					
					<li><a href="#method-i-mark_employee">#mark_employee</a></li>
					
					<li><a href="#method-i-mark_exception">#mark_exception</a></li>
					
					<li><a href="#method-i-mark_for_redo">#mark_for_redo</a></li>
					
					<li><a href="#method-i-result">#result</a></li>
					
					<li><a href="#method-i-result%3D">#result=</a></li>
					
					<li><a href="#method-i-succeeded%3F">#succeeded?</a></li>
					
					<li><a href="#method-i-time_taken">#time_taken</a></li>
					
				</ul>
			</div>
			

			<!-- Included Modules -->
			
		</div>

		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="../Gemfile.html">Gemfile</a></li>
				
					<li class="file"><a href="../MIT-LICENSE.html">MIT-LICENSE</a></li>
				
					<li class="file"><a href="../Rakefile.html">Rakefile</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="../images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="../JobBoss.html">JobBoss</a></li>
				
					<li><a href="../JobBoss/Boss.html">JobBoss::Boss</a></li>
				
					<li><a href="../JobBoss/Config.html">JobBoss::Config</a></li>
				
					<li><a href="../JobBoss/Job.html">JobBoss::Job</a></li>
				
					<li><a href="../JobBoss/Queuer.html">JobBoss::Queuer</a></li>
				
					<li><a href="../ActiveSupport.html">ActiveSupport</a></li>
				
					<li><a href="../ActiveSupport/TestCase.html">ActiveSupport::TestCase</a></li>
				
					<li><a href="../CreateJobs.html">CreateJobs</a></li>
				
					<li><a href="../DaemonTest.html">DaemonTest</a></li>
				
					<li><a href="../MathJobs.html">MathJobs</a></li>
				
					<li><a href="../Penguin.html">Penguin</a></li>
				
					<li><a href="../SleepJobs.html">SleepJobs</a></li>
				
					<li><a href="../StringJobs.html">StringJobs</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<h1 class="class">JobBoss::Job</h1>

		<div id="description">
			
		</div>

		<!-- Constants -->
		

		<!-- Attributes -->
		

		<!-- Methods -->
		
		<div id="public-class-method-details" class="method-section section">
			<h3 class="section-header">Public Class Methods</h3>

		
			<div id="delete-jobs-before-method" class="method-detail ">
				<a name="method-c-delete_jobs_before"></a>

				<div class="method-heading">
				
					<span class="method-name">delete_jobs_before</span><span
						class="method-args">(time)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Given a time object Delete all jobs which were completed earlier than that
time
</p>
					

					
					<div class="method-source-code"
						id="delete-jobs-before-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 164</span>
164:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_jobs_before</span>(<span class="ruby-identifier">time</span>)
165:         <span class="ruby-identifier">completed</span>.<span class="ruby-identifier">where</span>(<span class="ruby-value str">'completed_at &lt; ?'</span>, <span class="ruby-identifier">time</span>).<span class="ruby-identifier">delete_all</span>
166:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="result-hash-method" class="method-detail ">
				<a name="method-c-result_hash"></a>

				<div class="method-heading">
				
					<span class="method-name">result_hash</span><span
						class="method-args">(jobs)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Given a job or an array of jobs Returns a hash where the keys are the job
method arguments and the values are the results of the job processing
</p>
					

					
					<div class="method-source-code"
						id="result-hash-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 149</span>
149:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result_hash</span>(<span class="ruby-identifier">jobs</span>)
150:         <span class="ruby-identifier">jobs</span> = [<span class="ruby-identifier">jobs</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Job</span>)
151: 
152:         <span class="ruby-comment cmt"># the #result method automatically reloads the result here if needed but this will</span>
153:         <span class="ruby-comment cmt"># do it in one SQL call</span>
154:         <span class="ruby-identifier">jobs</span> = <span class="ruby-constant">Job</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">collect</span>(&amp;<span class="ruby-value">:id</span>))
155: 
156:         <span class="ruby-identifier">require</span> <span class="ruby-value str">'yaml'</span>
157:         <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hash</span>, <span class="ruby-identifier">job</span><span class="ruby-operator">|</span>
158:           <span class="ruby-identifier">hash</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">job</span>.<span class="ruby-identifier">args</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">job</span>.<span class="ruby-identifier">result</span>)
159:         <span class="ruby-keyword kw">end</span>
160:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="wait-for-jobs-method" class="method-detail ">
				<a name="method-c-wait_for_jobs"></a>

				<div class="method-heading">
				
					<span class="method-name">wait_for_jobs</span><span
						class="method-args">(jobs, sleep_interval = 0.5)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Given a job or an array of jobs Will cause the process to sleep until all
specified jobs have completed sleep_interval specifies polling period
</p>
					

					
					<div class="method-source-code"
						id="wait-for-jobs-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 133</span>
133:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">wait_for_jobs</span>(<span class="ruby-identifier">jobs</span>, <span class="ruby-identifier">sleep_interval</span> = <span class="ruby-value">0.5</span>)
134:         <span class="ruby-identifier">jobs</span> = [<span class="ruby-identifier">jobs</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Job</span>)
135: 
136:         <span class="ruby-identifier">ids</span> = <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">collect</span>(&amp;<span class="ruby-value">:id</span>)
137:         <span class="ruby-constant">Job</span>.<span class="ruby-identifier">uncached</span> <span class="ruby-keyword kw">do</span>
138:           <span class="ruby-keyword kw">until</span> <span class="ruby-constant">Job</span>.<span class="ruby-identifier">completed</span>.<span class="ruby-identifier">find_all_by_id</span>(<span class="ruby-identifier">ids</span>).<span class="ruby-identifier">count</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">jobs</span>.<span class="ruby-identifier">size</span>
139:             <span class="ruby-identifier">sleep</span>(<span class="ruby-identifier">sleep_interval</span>)
140:           <span class="ruby-keyword kw">end</span>
141:         <span class="ruby-keyword kw">end</span>
142: 
143:         <span class="ruby-keyword kw">true</span>
144:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="private-class-method-details" class="method-section section">
			<h3 class="section-header">Private Class Methods</h3>

		
			<div id="call-path-method" class="method-detail ">
				<a name="method-c-call_path"></a>

				<div class="method-heading">
				
					<span class="method-name">call_path</span><span
						class="method-args">(path, *args)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="call-path-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 196</span>
196:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_path</span>(<span class="ruby-identifier">path</span>, *<span class="ruby-identifier">args</span>)
197:         <span class="ruby-identifier">require</span> <span class="ruby-value str">'active_support'</span>
198:     
199:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid path (must have #)&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">match</span>(<span class="ruby-node">/.#./</span>)
200:         <span class="ruby-identifier">controller</span>, <span class="ruby-identifier">action</span> = <span class="ruby-identifier">path</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'#'</span>)
201:     
202:         <span class="ruby-identifier">controller_object</span> = <span class="ruby-keyword kw">begin</span>
203:           <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{controller.classify}Jobs&quot;</span>).<span class="ruby-identifier">new</span>
204:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
205:           <span class="ruby-keyword kw">begin</span>
206:             <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-node">&quot;#{controller.classify}&quot;</span>)
207:           <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
208:             <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid controller: #{controller}&quot;</span>
209:           <span class="ruby-keyword kw">end</span>
210:         <span class="ruby-keyword kw">end</span>
211:     
212:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid path action: #{action}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">controller_object</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">action</span>)
213:     
214:         <span class="ruby-identifier">controller_object</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">action</span>, *<span class="ruby-identifier">args</span>)
215:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="pending-paths-method" class="method-detail ">
				<a name="method-c-pending_paths"></a>

				<div class="method-heading">
				
					<span class="method-name">pending_paths</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="pending-paths-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 217</span>
217:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pending_paths</span>
218:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">pending</span>.<span class="ruby-identifier">except</span>(<span class="ruby-value">:order</span>).<span class="ruby-identifier">select</span>(<span class="ruby-value str">'DISTINCT path'</span>).<span class="ruby-identifier">collect</span>(&amp;<span class="ruby-value">:path</span>)
219:       <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="public-instance-method-details" class="method-section section">
			<h3 class="section-header">Public Instance Methods</h3>

		
			<div id="assigned--method" class="method-detail ">
				<a name="method-i-assigned%3F"></a>

				<div class="method-heading">
				
					<span class="method-name">assigned?</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Has the job been assigned to an employee?
</p>
					

					
					<div class="method-source-code"
						id="assigned--source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 98</span>
 98:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assigned?</span>
 99:       <span class="ruby-comment cmt"># If the #assigned? method is being called for but the job hasn't been completed, reload</span>
100:       <span class="ruby-comment cmt"># to check to see if it has been assigned</span>
101:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">employee_pid</span>.<span class="ruby-identifier">nil?</span>
102: 
103:       <span class="ruby-identifier">employee_pid</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">employee_host</span>
104:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="cancel-method" class="method-detail ">
				<a name="method-i-cancel"></a>

				<div class="method-heading">
				
					<span class="method-name">cancel</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Mark the job as cancelled so that the boss won&#8217;t run the job and so
that the employee running the job gets stopped (if it&#8217;s been
dispatched)
</p>
					

					
					<div class="method-source-code"
						id="cancel-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 83</span>
83:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancel</span>
84:       <span class="ruby-identifier">mark_as_cancelled</span>
85:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="cancelled--method" class="method-detail ">
				<a name="method-i-cancelled%3F"></a>

				<div class="method-heading">
				
					<span class="method-name">cancelled?</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Has the job been cancelled?
</p>
					

					
					<div class="method-source-code"
						id="cancelled--source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 88</span>
88:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cancelled?</span>
89:       <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">cancelled_at</span>
90:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="completed--method" class="method-detail ">
				<a name="method-i-completed%3F"></a>

				<div class="method-heading">
				
					<span class="method-name">completed?</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Is the job complete?
</p>
					

					
					<div class="method-source-code"
						id="completed--source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 77</span>
77:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">completed?</span>
78:       <span class="ruby-operator">!</span><span class="ruby-operator">!</span><span class="ruby-identifier">completed_at</span>
79:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="dispatch-method" class="method-detail ">
				<a name="method-i-dispatch"></a>

				<div class="method-heading">
				
					<span class="method-name">dispatch</span><span
						class="method-args">(boss)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Method used by the boss to dispatch an employee
</p>
					

					
					<div class="method-source-code"
						id="dispatch-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 15</span>
15:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">boss</span>)
16:       <span class="ruby-identifier">mark_as_started</span>
17:       <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Dispatching Job ##{self.id}&quot;</span>
18: 
19:       <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span> <span class="ruby-keyword kw">do</span>
20:         <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">reconnect!</span>
21:         <span class="ruby-identifier">$0</span> = <span class="ruby-node">&quot;[job_boss employee] job ##{self.id} #{self.path}(#{self.args.join(', ')})&quot;</span>
22:         <span class="ruby-constant">Process</span>.<span class="ruby-identifier">setpriority</span>(<span class="ruby-constant">Process</span><span class="ruby-operator">::</span><span class="ruby-constant">PRIO_PROCESS</span>, <span class="ruby-value">0</span>, <span class="ruby-value">19</span>)
23: 
24:         <span class="ruby-keyword kw">begin</span>
25:           <span class="ruby-identifier">mark_employee</span>
26: 
27:           <span class="ruby-identifier">value</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">call_path</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">path</span>, *<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">args</span>)
28: 
29:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-value">:result</span>, <span class="ruby-identifier">value</span>)
30:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>
31:           <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
32:           <span class="ruby-identifier">boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Error running job ##{self.id}!&quot;</span>
33:         <span class="ruby-keyword kw">ensure</span>
34:           <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">mark_as_completed</span>
35:             <span class="ruby-identifier">sleep</span>(<span class="ruby-value">1</span>)
36:           <span class="ruby-keyword kw">end</span>
37: 
38:           <span class="ruby-constant">Boss</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-node">&quot;Job ##{self.id} completed, exiting...&quot;</span>
39:           <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">exit</span>
40:         <span class="ruby-keyword kw">end</span>
41:       <span class="ruby-keyword kw">end</span>
42:       <span class="ruby-constant">Process</span>.<span class="ruby-identifier">detach</span>(<span class="ruby-identifier">pid</span>)
43:       <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">connection</span>.<span class="ruby-identifier">reconnect!</span>
44:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="error-method" class="method-detail ">
				<a name="method-i-error"></a>

				<div class="method-heading">
				
					<span class="method-name">error</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
If the job raised an exception, this method will return the instance of
that exception with the message and backtrace
</p>
					

					
					<div class="method-source-code"
						id="error-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 117</span>
117:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">error</span>
118:       <span class="ruby-comment cmt"># If the error is being called for but the job hasn't been completed, reload</span>
119:       <span class="ruby-comment cmt"># to check to see if there was a error</span>
120:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">error_message</span>.<span class="ruby-identifier">nil?</span>
121: 
122:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">error_class</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">error_message</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">error_backtrace</span>
123:         <span class="ruby-identifier">error</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">error_class</span>).<span class="ruby-identifier">new</span>(<span class="ruby-identifier">error_message</span>)
124:         <span class="ruby-identifier">error</span>.<span class="ruby-identifier">set_backtrace</span>(<span class="ruby-identifier">error_backtrace</span>)
125:         <span class="ruby-identifier">error</span>
126:       <span class="ruby-keyword kw">end</span>
127:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mark-for-redo-method" class="method-detail ">
				<a name="method-i-mark_for_redo"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_for_redo</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Clear out the job and put it back onto the queue for processing
</p>
					

					
					<div class="method-source-code"
						id="mark-for-redo-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 63</span>
63:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_for_redo</span>
64:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span>
65:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">started_at</span> = <span class="ruby-keyword kw">nil</span>
66:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">result</span> = <span class="ruby-keyword kw">nil</span>
67:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">completed_at</span> = <span class="ruby-keyword kw">nil</span>
68:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">status</span> = <span class="ruby-keyword kw">nil</span>
69:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_message</span> = <span class="ruby-keyword kw">nil</span>
70:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">error_backtrace</span> = <span class="ruby-keyword kw">nil</span>
71:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_host</span> = <span class="ruby-keyword kw">nil</span>
72:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">employee_pid</span> = <span class="ruby-keyword kw">nil</span>
73:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
74:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="result-method" class="method-detail ">
				<a name="method-i-result"></a>

				<div class="method-heading">
				
					<span class="method-name">result</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="result-source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 52</span>
52:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result</span>
53:       <span class="ruby-comment cmt"># If the result is being called for but the job hasn't been completed, reload</span>
54:       <span class="ruby-comment cmt"># to check to see if there was a result</span>
55:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">completed?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">read_attribute</span>(<span class="ruby-value">:result</span>).<span class="ruby-identifier">nil?</span>
56: 
57:       <span class="ruby-identifier">value</span> = <span class="ruby-identifier">read_attribute</span>(<span class="ruby-value">:result</span>)
58: 
59:       <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span>
60:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="result--method" class="method-detail ">
				<a name="method-i-result%3D"></a>

				<div class="method-heading">
				
					<span class="method-name">result=</span><span
						class="method-args">(value)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Store result as first and only value of an array so that the value always
gets serialized Was having issues with the boolean value of false getting
stored as the string &#8220;f&#8220;
</p>
					

					
					<div class="method-source-code"
						id="result--source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 48</span>
48:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">result=</span>(<span class="ruby-identifier">value</span>)
49:       <span class="ruby-identifier">write_attribute</span>(<span class="ruby-value">:result</span>, [<span class="ruby-identifier">value</span>])
50:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="succeeded--method" class="method-detail ">
				<a name="method-i-succeeded%3F"></a>

				<div class="method-heading">
				
					<span class="method-name">succeeded?</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
Did the job succeed?
</p>
					

					
					<div class="method-source-code"
						id="succeeded--source">
<pre>
    <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 93</span>
93:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">succeeded?</span>
94:       <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">&amp;&amp;</span> (<span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'success'</span>)
95:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="time-taken-method" class="method-detail ">
				<a name="method-i-time_taken"></a>

				<div class="method-heading">
				
					<span class="method-name">time_taken</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					<p>
How long did the job take?
</p>
					

					
					<div class="method-source-code"
						id="time-taken-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 107</span>
107:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">time_taken</span>
108:       <span class="ruby-comment cmt"># If the #time_taken method is being called for but the job doesn't seem to have started/completed</span>
109:       <span class="ruby-comment cmt"># reload to see if it has</span>
110:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">reload</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">started_at</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">completed_at</span>.<span class="ruby-identifier">nil?</span>
111: 
112:       <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">started_at</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">completed_at</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">started_at</span>
113:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	
		<div id="private-instance-method-details" class="method-section section">
			<h3 class="section-header">Private Instance Methods</h3>

		
			<div id="mark-as-cancelled-method" class="method-detail ">
				<a name="method-i-mark_as_cancelled"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_as_cancelled</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="mark-as-cancelled-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 175</span>
175:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_cancelled</span>
176:       <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:cancelled_at</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
177:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mark-as-completed-method" class="method-detail ">
				<a name="method-i-mark_as_completed"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_as_completed</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="mark-as-completed-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 189</span>
189:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_completed</span>
190:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">status</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">'success'</span>
191:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">completed_at</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
192:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">save</span>
193:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mark-as-started-method" class="method-detail ">
				<a name="method-i-mark_as_started"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_as_started</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="mark-as-started-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 171</span>
171:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_as_started</span>
172:       <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:started_at</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)
173:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mark-employee-method" class="method-detail ">
				<a name="method-i-mark_employee"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_employee</span><span
						class="method-args">()</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="mark-employee-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 179</span>
179:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_employee</span>
180:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'socket'</span>
181:       <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:employee_host</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">gethostname</span>,
182:                         <span class="ruby-value">:employee_pid</span>     =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">pid</span>)
183:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
			<div id="mark-exception-method" class="method-detail ">
				<a name="method-i-mark_exception"></a>

				<div class="method-heading">
				
					<span class="method-name">mark_exception</span><span
						class="method-args">(exception)</span>
					<span class="method-click-advice">click to toggle source</span>
				
				</div>

				<div class="method-description">
					
					
					

					
					<div class="method-source-code"
						id="mark-exception-source">
<pre>
     <span class="ruby-comment cmt"># File lib/job_boss/job.rb, line 185</span>
185:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mark_exception</span>(<span class="ruby-identifier">exception</span>)
186:       <span class="ruby-identifier">update_attributes</span>(<span class="ruby-value">:status</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">'error'</span>, <span class="ruby-value">:error_class</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-value">:error_message</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">message</span>, <span class="ruby-value">:error_backtrace</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">backtrace</span>)
187:     <span class="ruby-keyword kw">end</span></pre>
					</div>
					
				</div>

				

				
			</div>

		
		</div>
	

	</div>


	<div id="rdoc-debugging-section-dump" class="debugging-section">
	
		<p>Disabled; run with --debug to generate this.</p>
	
	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>

</body>
</html>

